package org.edu.modules.act.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.activiti.bpmn.model.BpmnModel;
import org.activiti.bpmn.model.FlowNode;
import org.activiti.bpmn.model.SequenceFlow;
import org.activiti.core.common.spring.security.policies.ActivitiForbiddenException;
import org.activiti.engine.*;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.history.HistoricTaskInstanceQuery;
import org.activiti.engine.impl.identity.Authentication;
import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.Execution;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.*;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.edu.modules.act.common.result.PaginationBuilder;
import org.edu.modules.act.entity.*;
import org.edu.modules.act.mapper.*;
import org.edu.modules.act.service.WordOnlineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 任务信息的业务逻辑实现层
 *
 * @版权所有 福州土著人信息科技有限公司
 */
@Service
@Transactional
public class TaskServiceImpl implements org.edu.modules.act.service.TaskService {

	private static final String FINISHED = "finished";
	private static final String ASSIGNEE = "assignee";
	private static final String CANDIDATE = "candidate";

	@Autowired
	private TaskService taskService;

	@Autowired
	private RuntimeService runtimeService;

	@Autowired
	private HistoryService historyService;

	@Autowired
	private RepositoryService repositoryService;

	@Resource
	private ActRuInstanceFileMapper actRuInstanceFileMapper;
	@Autowired
	private org.edu.modules.act.service.TaskService turenTaskService;

	@Resource
	private ActReModelMapper actReModelMapper;

	@Resource
	private IVeBaseTeacherMapper iVeBaseTeacherMapper;
	@Resource
	private VeBaseDepartmentMapper veBaseDepartmentMapper;

	@Resource
	private ActReWordModelMapper actReWordModelMapper;

	@Autowired
	private WordOnlineService wordOnlineService;
	/**
	 * 查询任务分页
	 */
	@Override
	public Map<String, Object> queryTask(Integer currentPage, Integer pageSize, String taskName) {
		TaskQuery taskQuery = taskService.createTaskQuery();
		if (StringUtils.isNotBlank(taskName)) {
			taskQuery.taskNameLike("%" + taskName + "%");
		}
		List<Task> taskList = taskQuery.includeProcessVariables().includeTaskLocalVariables().orderByTaskPriority().desc()
				.listPage(pageSize * (currentPage - 1), pageSize);
		List<LinkedHashMap<String, Object>> resultList = new ArrayList<>();
		for (int i = 0; i < taskList.size(); i++) {
			LinkedHashMap<String, Object> taskMap = new LinkedHashMap<>();
			taskMap.put("id", taskList.get(i).getId());
			taskMap.put(ASSIGNEE, taskList.get(i).getAssignee());
			taskMap.put("category", taskList.get(i).getCategory());
			taskMap.put("claimTime", taskList.get(i).getClaimTime());
			taskMap.put("createTime", taskList.get(i).getCreateTime());
			taskMap.put("delegationState", taskList.get(i).getDelegationState());
			taskMap.put("description", taskList.get(i).getDescription());
			taskMap.put("dueDate", taskList.get(i).getDueDate());
			taskMap.put("executionId", taskList.get(i).getExecutionId());
			taskMap.put("formKey", taskList.get(i).getFormKey());
			taskMap.put("suspended", taskList.get(i).isSuspended());
			taskMap.put("name", taskList.get(i).getName());
			taskMap.put("owner", taskList.get(i).getOwner());
			taskMap.put("parentTaskId", taskList.get(i).getParentTaskId());
			taskMap.put("priority", taskList.get(i).getPriority());
			taskMap.put("processDefinitionId", taskList.get(i).getProcessDefinitionId());
			taskMap.put("processInstanceId", taskList.get(i).getProcessInstanceId());
			taskMap.put("processVariables", taskList.get(i).getProcessVariables());
			taskMap.put("taskDefinitionKey", taskList.get(i).getTaskDefinitionKey());
			taskMap.put("taskLocalVariables", taskList.get(i).getTaskLocalVariables());
			taskMap.put("tenantId", taskList.get(i).getTenantId());
			ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(taskList.get(i).getProcessInstanceId())
					.singleResult();
			taskMap.put("processDefinitionName", processInstance.getProcessDefinitionName());
			taskMap.put("startUserId", processInstance.getStartUserId());
			List<Comment> commentList = taskService.getProcessInstanceComments(taskList.get(i).getProcessInstanceId());// 查询该流程实例ID的所有批注 NOSONAR
			List<String> comments = new ArrayList<>();
			for (int j = 0; j < commentList.size(); j++) {
				comments.add(commentList.get(j).getUserId() + "：" + commentList.get(j).getFullMessage() + "\n");
			}

			taskMap.put("comments", comments);
			resultList.add(taskMap);
		}

//		org.springframework.security.core.Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
//		String roleData = sysRoleServiceClient.queryRoleData("task", authentication.getName());
//		String[] roleDataArray = roleData == null ? null : roleData.split(",");
//		if (roleDataArray != null && roleDataArray.length > 0) {// 处理数据权限
//			return PaginationBuilder.buildResult(CollectionUtils.convertFilterList(resultList, roleDataArray), taskQuery.count(), currentPage, pageSize);
//		} else {
//			return PaginationBuilder.buildResult(resultList, taskQuery.count(), currentPage, pageSize);
//		}
		return PaginationBuilder.buildResult(resultList, taskQuery.count(), currentPage, pageSize);
	}

	/**
	 * 编辑任务
	 */
	@Override
	public void updateTask(String taskId, String candidate) {
		Task task = checkTask(taskId);
		taskService.addCandidateUser(task.getId(), candidate);
		taskService.addUserIdentityLink(task.getId(), candidate, IdentityLinkType.OWNER);
	}

	/**
	 * 签收任务
	 */
	@Override
	public void claimTask(String taskId, String assignee) {
		Task task = checkTask(taskId);
		taskService.claim(task.getId(), assignee);
	}

	/**
	 * 完结任务，任务进入下一节点
	 */
	@Override
	public void completeTask(String taskId, String processInstanceId, String candidate, String comment, String username) {
		Task task = checkTask(taskId);
		Map<String, Object> variablesMap = new HashMap<>();
		Authentication.setAuthenticatedUserId(username);
		taskService.addComment(task.getId(), processInstanceId, comment);
		variablesMap.put("approved", true);

		//请假分支，条件判断
		//获取该流程实例绑定的文件表数据获取url和表单
		QueryWrapper<ActRuInstanceFileEntity> wrapper=new QueryWrapper<>();
		wrapper.eq("PROC_INST_ID",processInstanceId);
		List<ActRuInstanceFileEntity> list = actRuInstanceFileMapper.selectList(wrapper);
		if(list.size()>0) {
			String h5 = list.get(0).getWordFileUrl();
			if(h5!=null){
				int start = h5.indexOf("[[");
				int end = h5.indexOf("]]");
				if(start<end){
					//获取请假天数  如： [[ 5 ]]
					String dayString = h5.substring(start+2,end);
//					System.out.println("dayString1=   " + dayString);
					dayString = dayString.replace("&nbsp;","");
					dayString = dayString.replace(" ","");
//					System.out.println("dayString2=   " + dayString);
					int day = Integer.parseInt(dayString);
					//将请假天数，加入到判断条件中
					variablesMap.put("day", day);
				}
			}
		}


		taskService.complete(task.getId(), variablesMap);
		Task nextTask = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
		String approvedBy="";
		System.out.println(nextTask);
		if (nextTask != null) {
			taskService.addCandidateUser(nextTask.getId(), approvedBy);
			taskService.addUserIdentityLink(nextTask.getId(), approvedBy, IdentityLinkType.CANDIDATE);
			BpmnModel bpmnModel = repositoryService.getBpmnModel(nextTask.getProcessDefinitionId());
			List<org.activiti.bpmn.model.Process> processList = bpmnModel.getProcesses();
			approvedBy =processList.get(0).getFlowElement(nextTask.getTaskDefinitionKey()).getAttributes().get("assignee").get(0).getValue();
			taskService.addCandidateUser(nextTask.getId(), approvedBy);
			taskService.addUserIdentityLink(nextTask.getId(), approvedBy, IdentityLinkType.CANDIDATE);
			turenTaskService.claimTask(nextTask.getId(), approvedBy);//直接签收 流到待操作
		} else {
			if (StringUtils.isNotBlank(approvedBy)) {
				throw new ActivitiIllegalArgumentException("您是此流程最后审批人员，请选择结束");
			}
		}
	}
	/**
	 * 委派任务
	 */
	@Override
	public void delegateTask(String taskId, String processInstanceId, String comment, String username, String assignee) {
		if (StringUtils.isBlank(assignee)) {
			throw new ActivitiIllegalArgumentException("审批人员不能为空");
		}
		Task task = checkTask(taskId);
		Authentication.setAuthenticatedUserId(username);
		taskService.addComment(task.getId(), processInstanceId, comment);
		taskService.delegateTask(task.getId(), assignee);
	}

	/**
	 * 被委派人完结任务并返回
	 */
	@Override
	public void resolveTask(String taskId, String processInstanceId, String comment, String username) {
		Task task = checkTask(taskId);
		Authentication.setAuthenticatedUserId(username);
		taskService.addComment(task.getId(), processInstanceId, comment);
		taskService.resolveTask(task.getId());
	}

	/**
	 * 回退任务
	 */
	@Override
	public void regressTask(String taskId, String processInstanceId, String comment, String username) {
		Task task = checkTask(taskId);

		// 取得所有历史任务按时间降序排序
		List<HistoricTaskInstance> htiList = historyService.createHistoricTaskInstanceQuery()
				.processInstanceId(processInstanceId)
				.orderByTaskCreateTime()
				.desc()
				.list();
		if (ObjectUtils.isEmpty(htiList) || htiList.size() < 2) {
			return;
		}
		// list里的第二条代表上一个任务
		HistoricTaskInstance lastTask = htiList.get(1);
		// list里第二条代表当前任务
		HistoricTaskInstance curTask = htiList.get(0);
		// 当前节点的executionId
		String curExecutionId = curTask.getExecutionId();
		// 上个节点的taskId
		String lastTaskId = lastTask.getId();
		// 上个节点的executionId
		String lastExecutionId = lastTask.getExecutionId();
		if (null == lastTaskId) {
			throw new ActivitiIllegalArgumentException("没有可回退的用户任务");
		}
		Authentication.setAuthenticatedUserId(username);
		taskService.addComment(task.getId(), processInstanceId, comment);
		String processDefinitionId = lastTask.getProcessDefinitionId();
		BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
		String lastActivityId = null;
		List<HistoricActivityInstance> haiFinishedList = historyService.createHistoricActivityInstanceQuery()
				.executionId(lastExecutionId).finished().list();
		for (HistoricActivityInstance hai : haiFinishedList) {
			if (lastTaskId.equals(hai.getTaskId())) {
				// 得到ActivityId，只有HistoricActivityInstance对象里才有此方法
				lastActivityId = hai.getActivityId();
				break;
			}
		}
		// 得到上个节点的信息
		FlowNode lastFlowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(lastActivityId);
		// 取得当前节点的信息
		Execution execution = runtimeService.createExecutionQuery().executionId(curExecutionId).singleResult();
		String curActivityId = execution.getActivityId();
		FlowNode curFlowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(curActivityId);
		//记录当前节点的原活动方向
		List<SequenceFlow> oriSequenceFlows = new ArrayList<>();
		oriSequenceFlows.addAll(curFlowNode.getOutgoingFlows());
		//清理活动方向
		curFlowNode.getOutgoingFlows().clear();
		//建立新方向
		List<SequenceFlow> newSequenceFlowList = new ArrayList<>();
		SequenceFlow newSequenceFlow = new SequenceFlow();
		newSequenceFlow.setId("newSequenceFlowId");
		newSequenceFlow.setSourceFlowElement(curFlowNode);
		newSequenceFlow.setTargetFlowElement(lastFlowNode);
		newSequenceFlowList.add(newSequenceFlow);
		curFlowNode.setOutgoingFlows(newSequenceFlowList);
		// 完成任务
		taskService.complete(task.getId());
		//恢复原方向
		curFlowNode.setOutgoingFlows(oriSequenceFlows);
		org.activiti.engine.task.Task nextTask = taskService
				.createTaskQuery().processInstanceId(processInstanceId).singleResult();
		// 设置执行人
		if(nextTask!=null) {
			taskService.setAssignee(nextTask.getId(), lastTask.getAssignee());
		}
	}

	/**
	 * 驳回任务
	 */
	@Override
	public void rejectTask(String taskId, String processInstanceId, String comment, String username) {
		Task task = checkTask(taskId);
		Authentication.setAuthenticatedUserId(username);
		taskService.addComment(task.getId(), processInstanceId, comment);
		while (true) {
			Task nextTask = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
			if (nextTask == null) {
				break;
			}
			Map<String, Object> variablesMap = new HashMap<>();
			taskService.setVariable(nextTask.getId(), "approved", false);
			taskService.complete(nextTask.getId(), variablesMap);
		}
	}

	/**
	 * 终止任务
	 */
	@Override
	public void terminateTask(String taskId, String processInstanceId, String comment, String username) {
		Task task = checkTask(taskId);
		Authentication.setAuthenticatedUserId(username);
		taskService.addComment(task.getId(), processInstanceId, comment);
		runtimeService.deleteProcessInstance(processInstanceId, comment);
	}

	/**
	 * 删除任务
	 */
	@Override
	public void deleteTask(String taskId) {
		Task task = checkTask(taskId);
		if (task.getExecutionId() != null) {
			throw new ActivitiForbiddenException("包含流程实例中的任务，不能删除");
		}
		taskService.deleteTask(task.getId(), "ID为" + task.getId() + "的任务已删除", true);
	}

	/**
	 * 校验任务是否存在和是否挂起
	 */
	private Task checkTask(String taskId) {
		Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
		if (task == null) {
			throw new ActivitiObjectNotFoundException("找不到ID为'" + taskId + "'的任务", Task.class);
		}
		if (task.isSuspended()) {
			throw new ActivitiForbiddenException("流程实例已挂起，不能操作");
		}
		return task;
	}

	/**
	 * 查询个人任务分页
	 */
	@Override
	public Map<String, Object> queryPersonalTask(Integer currentPage, Integer pageSize, String username, String taskName, String taskStatus) {
		TaskInfoQueryWrapper taskInfoQueryWrapper = null;
		if (FINISHED.equals(taskStatus)) {// 已办
			HistoricTaskInstanceQuery historicTaskInstanceQuery = historyService.createHistoricTaskInstanceQuery();
			historicTaskInstanceQuery.taskAssignee(username).finished();
			taskInfoQueryWrapper = new TaskInfoQueryWrapper(historicTaskInstanceQuery);
		} else if (ASSIGNEE.equals(taskStatus)) {// 待办
			taskInfoQueryWrapper = new TaskInfoQueryWrapper(taskService.createTaskQuery().taskAssignee(username));
		} else if (CANDIDATE.equals(taskStatus)) {// 待签收
			taskInfoQueryWrapper = new TaskInfoQueryWrapper(taskService.createTaskQuery().taskCandidateUser(username));
		}
		if (StringUtils.isNotBlank(taskName)) {
			taskInfoQueryWrapper.getTaskInfoQuery().taskNameLike("%" + taskName + "%");
		}
		List<? extends TaskInfo> taskInfoList = taskInfoQueryWrapper.getTaskInfoQuery().includeProcessVariables().includeTaskLocalVariables()
				.orderByTaskCreateTime().desc().listPage(pageSize * (currentPage - 1), pageSize);
		List<LinkedHashMap<String, Object>> resultList = new ArrayList<>();
		for (int i = 0; i < taskInfoList.size(); i++) {
			LinkedHashMap<String, Object> taskMap = new LinkedHashMap<>();
			taskMap.put("id", taskInfoList.get(i).getId());

			taskMap.put(ASSIGNEE, taskInfoList.get(i).getAssignee());
			taskMap.put("category", taskInfoList.get(i).getCategory());
			taskMap.put("claimTime", taskInfoList.get(i).getClaimTime());
			taskMap.put("createTime", taskInfoList.get(i).getCreateTime());
			taskMap.put("description", taskInfoList.get(i).getDescription());
			taskMap.put("dueDate", taskInfoList.get(i).getDueDate());
			taskMap.put("executionId", taskInfoList.get(i).getExecutionId());
			taskMap.put("formKey", taskInfoList.get(i).getFormKey());
			taskMap.put("name", taskInfoList.get(i).getName());
			taskMap.put("owner", taskInfoList.get(i).getOwner());
			taskMap.put("parentTaskId", taskInfoList.get(i).getParentTaskId());
			taskMap.put("priority", taskInfoList.get(i).getPriority());
			taskMap.put("processDefinitionId", taskInfoList.get(i).getProcessDefinitionId());
			taskMap.put("processInstanceId", taskInfoList.get(i).getProcessInstanceId());
			taskMap.put("processVariables", taskInfoList.get(i).getProcessVariables());
			taskMap.put("taskDefinitionKey", taskInfoList.get(i).getTaskDefinitionKey());
			taskMap.put("taskLocalVariables", taskInfoList.get(i).getTaskLocalVariables());
			taskMap.put("tenantId", taskInfoList.get(i).getTenantId());
			ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) repositoryService
					.getProcessDefinition(taskInfoList.get(i).getProcessDefinitionId());
			taskMap.put("processDefinitionName", processDefinition.getName());
			List<Comment> commentList = taskService.getProcessInstanceComments(taskInfoList.get(i).getProcessInstanceId());// 查询该流程实例ID的所有批注 NOSONAR
			List<String> comments = new ArrayList<>();

			for (int j = 0; j < commentList.size(); j++) {
				SimpleDateFormat sdf =   new SimpleDateFormat( " yyyy-MM-dd HH:mm:ss " );
				String str = sdf.format(commentList.get(j).getTime());
				QueryWrapper<VeBaseTeacherEntity> wrapper3=new QueryWrapper<>();
				wrapper3.eq("userId", commentList.get(j).getUserId());
				List<VeBaseTeacherEntity> list3 = iVeBaseTeacherMapper.selectList(wrapper3);
				comments.add(list3.get(0).getXM() + "," + commentList.get(j).getFullMessage() +","+str+ ","+commentList.get(j).getUserId());
			}
			taskMap.put("comments", comments);
			Task delegationTask = taskService.createTaskQuery().taskId(taskInfoList.get(i).getId()).singleResult();
			if (delegationTask != null) {
				taskMap.put("delegationState", delegationTask.getDelegationState());
			}
			HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery()
					.processInstanceId(taskInfoList.get(i).getProcessInstanceId()).singleResult();
			taskMap.put("processInstanceName", historicProcessInstance.getName());
			//获取任务的状态（待审批、审批通过）
			ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
			ProcessInstance singleResult = processEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(taskInfoList.get(i).getProcessInstanceId()).singleResult();
			String state="";

			if( historicProcessInstance.getDeleteReason()!=null&&historicProcessInstance.getEndTime()!=null){
				state="已终止";
			} else if (singleResult == null) {
				state="审批通过";
			} else {
				state="待审批";
			}

			taskMap.put("state",state);

			//查询部署ID

			List<ProcessDefinition> li = processEngine.getRepositoryService()
					.createProcessDefinitionQuery()
					.processDefinitionId(taskInfoList.get(i).getProcessDefinitionId())//使用流程定义ID查询
					.list();
			String deploymentId = li.get(0).getDeploymentId();

			//根据部署ID去查找模型
			QueryWrapper<ActReModelEntity> wrapper1=new QueryWrapper<>();
			wrapper1.eq("DEPLOYMENT_ID_",deploymentId);
			List<ActReModelEntity> list1 = actReModelMapper.selectList(wrapper1);
			taskMap.put("modelInfo",list1.get(0));


			//获取该流程实例绑定的文件表数据获取url和表单
			QueryWrapper<ActRuInstanceFileEntity> wrapper=new QueryWrapper<>();
			wrapper.eq("PROC_INST_ID",taskInfoList.get(i).getProcessInstanceId());
			List<ActRuInstanceFileEntity> list = actRuInstanceFileMapper.selectList(wrapper);

			String h5 = list.get(0).getWordFileUrl();

			//根据ModelId去查找模板的url
			String modelId = list1.get(0).getId();
			QueryWrapper<ActReWordModel> wrapper5 = new QueryWrapper();
			wrapper5.eq("MODEL_ID",modelId);
			//获取该实例的word模板
			List<ActReWordModel> wordList = actReWordModelMapper.selectList(wrapper5);

			//
			String oldH5 = wordList.get(0).getWordH5();
			String[] split = oldH5.split("\\{\\{auditOpinion1\\}\\}");
			String save=split[0].substring(split[0].length()-300);
			String[] header=h5.split(save);
			String[] end = oldH5.split(save);
			String newH5=header[0]+save+end[1];

			//获取表单的h5的代码

			Map<String ,String > map= new LinkedHashMap<>();
			for (int j = comments.size()-1; j >=0 ; j--) {
				String[] arr = comments.get(j).split(",");
				map.put(arr[3],comments.get(j));
			}
			//替换标识符为回填消息
			Set<Map.Entry<String, String>> entries = map.entrySet();
			int mark=1;
			for(Map.Entry entry : entries ){
				String comm=entry.toString().split("=")[1];
				String[] arr=comm.split(",");
				newH5 = newH5.replace("{{auditOpinion"+mark+"}}",arr[1]);
				newH5 = newH5.replace("{{auditName"+mark+"}}",arr[0]);
				newH5 = newH5.replace("{{auditTime"+mark+"}}",arr[2]);
				mark++;
			}
			for (int j = map.size(); j < 10; j++) {
				newH5 = newH5.replace("{{auditOpinion"+j+"}}","");
				newH5 = newH5.replace("{{auditName"+j+"}}","");
				newH5 = newH5.replace("{{auditTime"+j+"}}","");
			}

			list.get(0).setWordFileUrl(newH5);
			taskMap.put("wordAndAccessUrl",list.get(0));
			//根据实例ID去查找开始用户ID
			HistoricProcessInstance processInstance= ProcessEngines.getDefaultProcessEngine().
					getHistoryService().createHistoricProcessInstanceQuery().
					processInstanceId(taskInfoList.get(i).getProcessInstanceId()).singleResult();
			String startUserId = processInstance.getStartUserId();
			//查询我的任务时，获取用户信息（taecher表）
			QueryWrapper<VeBaseTeacherEntity> wrapper2 = new QueryWrapper<>();
			wrapper2.eq("userId",startUserId);
			List<VeBaseTeacherEntity> list2 = iVeBaseTeacherMapper.selectList(wrapper2);
			taskMap.put("startUserInfo", list2.get(0));

			//获取该用户的部门信息
			QueryWrapper<VeBaseDepartment> wrapper4 = new QueryWrapper<>();
			wrapper4.eq("id",list2.get(0).getDepId());
			List<VeBaseDepartment> list3 = veBaseDepartmentMapper.selectList(wrapper4);
			taskMap.put("startUserDepartment", list3.get(0));

			resultList.add(taskMap);

		}

//		org.springframework.security.core.Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
//		String roleData = sysRoleServiceClient.queryRoleData("candidatetask", authentication.getName());
//		String[] roleDataArray = roleData == null ? null : roleData.split(",");
//		if (roleDataArray != null && roleDataArray.length > 0) {// 处理数据权限
//			return PaginationBuilder.buildResult(CollectionUtils.convertFilterList(resultList, roleDataArray), taskInfoQueryWrapper.getTaskInfoQuery().count(),
//					currentPage, pageSize);
//		} else {
//			return PaginationBuilder.buildResult(resultList, taskInfoQueryWrapper.getTaskInfoQuery().count(), currentPage, pageSize);
//		}
		return PaginationBuilder.buildResult(resultList, taskInfoQueryWrapper.getTaskInfoQuery().count(), currentPage, pageSize);



	}

	/**
	 * 查询任务批注
	 */
	@Override
	public Map<String, Object> queryTaskComment(String processInstanceId) {
		Map<String, Object> map = new HashMap<>();
		List<Comment> commentList = taskService.getProcessInstanceComments(processInstanceId);
		map.put("list", commentList);
		return map;
	}

}
